import 'dart:convert';

import 'package:crypto/crypto.dart';
import 'package:encrypt/encrypt.dart';
import 'package:convert/convert.dart';

class Encrypt {
  // Aes 加密
  static String aesEncrypt(String data) {
    // final plainText =
    //     "Maps_Func_sales_mk('MUJI','MUJI_SH','500088','','01','31','*','','1','31','')";

    final key = Key.fromUtf8("jt25mm1ayc9wdx4q");
    final iv = IV.fromUtf8("");
    final encrypter = Encrypter(AES(key, mode: AESMode.ecb, padding: 'PKCS7'));

    final encrypted = encrypter.encrypt(data, iv: iv);
    // final decrypted = encrypter.decrypt(encrypted, iv: iv);
    // print(encrypted.base64);

    return encrypted.base64;
    // print(decrypted);
    // print(encrypted.bytes);
    // print(encrypted.base16);
  }

  // MD5加密
  static String md5Encryp(String data) {
    var content =
        new Utf8Encoder().convert(data + "glgzkgn58jexsbcvjt25mm1ayc9wdx4q");
    var digest = md5.convert(content);
    // 这里其实就是 digest.toString()
    // print(hex.encode(digest.bytes));
    return hex.encode(digest.bytes);
  }
}
